<?php 
class class_nguoiban extends database
{
		
	function ListNguoiBanViewNhieuNhat()
	{
		$this->setQuery('set names utf8');
		$this->Query();

		$sql = 'select *
				from nguoi_ban
				where Username is not NULL
				order by PageView desc limit 0,3';

		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;		
	}
	
	function CountListNguoiBanViewNhieuNhat()
	{
		$sql = 'select * 
				from nguoi_ban
				where Username is not NULL';

		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		$num = count($table);
		return $num;
	}
	
	function ChiTietNguoiBan($MaNguoiBan)
	{
		$this->setQuery('set names utf8');
		$this->Query();

		$sql = 'select *
				from nguoi_ban
				where MaSo='.$MaNguoiBan;

		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;		
	}
	
	// //////////////////////////////// Đăng Ký tài khoản ////////////////////////////////////////////
	
	function KiemTraTonTaiUserName($tendangnhap)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from nguoi_ban where Username=\''.$tendangnhap.'\'';	
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function KiemTraTonTaiEmail($email)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from nguoi_ban where Username is not NULL and Email=\''.$email.'\'';
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function themmoi($tendangnhap,$matkhau,$email,$hoten,$diachi,$dienthoai,$gioitinh,$ngaysinh,$hinhanh)
	{
		$timezone  = 7;
		$ngaydangky = gmdate("Y/m/d H:i:s", time() + 3600*($timezone+date("I"))); 

		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'insert into nguoi_ban(Username, Password, Email, HoTen, DiaChi, DienThoai, GioiTinh, NgaySinh, HinhAnh, NgayDangKy) values("'.$tendangnhap.'","'.$matkhau.'","'.$email.'","'.$hoten.'","'.$diachi.'","'.$dienthoai.'",'.$gioitinh.',"'.$ngaysinh.'","'.$hinhanh.'","'.$ngaydangky.'")';
				
		$this->setQuery($sql);
		$kq = $this->Query();
		$manhomsv = mysql_insert_id();
		return $manhomsv;
	}
	
	// đăng nhập /////////////////////////////////////////////////////////////////////////////
	
	function kiemtraacc($user, $pass)
	{
		$pass = md5($pass);
		$sql = 'select * from nguoi_ban where Username=\''.$user.'\' and Password=\''.$pass.'\'';		
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}

}
?>